import { isFunction } from '@vue/shared'

const useMounted = (fn) => {
    const func = isFunction(fn) ? fn : () => { }
    const instance = getCurrentInstance()

    const result = ref({})

    if (!instance) {
        result.value = func()
        return result
    }
    let timeout = null
    onActivated(() => {
        clearTimeout(timeout)
        timeout = setTimeout(() => {
            result.value = func()
        });

    })

    onMounted(() => {
        timeout = setTimeout(() => {
            result.value = func()
        })
    });
    return result
}

export default useMounted